(function(window){
	let Bg = window.Bg = function() {
		this.x = 0	//x坐标
		let bgRandom = Math.round(Math.random()*1)	//随机背景（昼夜）
		this.oImg = [myGame.bg_day,myGame.bg_night][bgRandom]	//背景
		this.height = myGame.c.height * 0.85	//背景高度
		this.fillStyleColor = bgRandom?'#008793':'#4ec0ca'	//背景填充色
	}
	
	//更新x坐标
	Bg.prototype.update = function () {
		this.x -= myGame.bgSpeed
		//循环
		if(this.x < -this.oImg.width) this.x = 0
	}
	
	//渲染
	Bg.prototype.render = function () {
		//平铺
		for (var i =0; i <= Math.ceil(myGame.c.width/this.oImg.width); i++) {
			myGame.ctx.drawImage(
				this.oImg,
				this.x+this.oImg.width*i, 
				this.height - this.oImg.height, 
				this.oImg.width,
				this.oImg.height
			)
		}
		
		//补齐背景
		if(this.oImg.height<this.height){
			myGame.ctx.save()
			myGame.ctx.fillStyle = this.fillStyleColor
			myGame.ctx.fillRect(0,0,myGame.c.width,this.height-this.oImg.height+1)
			myGame.ctx.restore()
		}
	}
})(window)